<!DOCTYPE html>
<html lang="en">

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Porting to GCC 12</title>
<link rel="stylesheet" type="text/css" href="https://gcc.gnu.org/gcc.css" />
</head>

<body>
<h1>Porting to GCC 12</h1>

<p>
The GCC 12 release series differs from previous GCC releases in
<a href="changes.html">a number of ways</a>. Some of these are a result
of bug fixing, and some old behaviors have been intentionally changed
to support new standards, or relaxed in standards-conforming ways to
facilitate compilation or run-time performance.
</p>

<p>
Some of these changes are user visible and can cause grief when
porting to GCC 12. This document is an effort to identify common issues
and provide solutions. Let us know if you have suggestions for improvements!
</p>


<!--
<h2 id="cpp">Preprocessor issues</h2>
-->
<h2 id="c">C language issues</h2>

<h3 id="computedgotos">Computed goto now requires a pointer type</h3>

<p>
In GCC 12, a computed goto requires a pointer type.
An example which was accepted before:</p>
<pre><code>
  void f(void)
  {
    goto *10;
  }
</code></pre>
is no longer accepted and you need to add a cast to it like:

<pre><code>
  void f(void)
  {
    goto *(void*)10;
  }
</code></pre>

<h2 id="cxx">C++ language issues</h2>

<h3 id="header-dep-changes">Header dependency changes</h3>
<p>Some C++ Standard Library headers have been changed to no longer include
other headers that were being used internally by the library.
As such, C++ programs that used standard library components without
including the right headers will no longer compile.
</p>
<p>
The following headers are used less widely in libstdc++ and may need to
be included explicitly when compiled with GCC 12:
</p>
<ul>
<li> <code>&lt;memory&gt;</code>
  (for <code>std::shared_ptr</code>, <code>std::unique_ptr</code> etc.)
</li>
<li> <code>&lt;iterator&gt;</code>
  (for <code>std::begin</code>, <code>std::end</code>, <code>std::size</code>,
  <code>std::istream_iterator</code>, <code>std::istreambuf_iterator</code>)
</li>
<li> <code>&lt;algorithm&gt;</code>
  (for <code>std::for_each</code>, <code>std::copy</code> etc.)
</li>
<li> <code>&lt;utility&gt;</code>
  (for <code>std::pair</code>)
</li>
<li> <code>&lt;array&gt;</code>
  (for <code>std::array</code>)
</li>
<li> <code>&lt;atomic&gt;</code>
  (for <code>std::atomic</code>)
</li>
<li> <code>&lt;ctime&gt;</code>
  (for <code>std::time</code>, <code>std::mktime</code> etc.)
</li>
<li> <code>&lt;pthread.h&gt;</code>
  (for <code>pthread_create</code>, <code>pthread_mutex_t</code> etc.)
</li>
</ul>

<h3 id="cxx-deprecations">C++ Standard Library deprecations</h3>
<p>
Warnings have been added for use of C++ standard library features that
are deprecated (or no longer present at all) in recent C++ standards.
Where possible, the warning suggests a modern replacement for the
deprecated feature.
</p>
<p>
The <code>std::iterator</code> base class can usually be replaced by defining
the same necessary typedefs directly in your iterator class.
The <code>std::unary_function</code> and <code>std::binary_function</code>
base classes can often be completely removed, or the typedefs for
<code>result_type</code> and argument types can be defined directly in your
class.
</p>

<h2 id="fortran">Fortran language issues</h2>

<h3 id="co_reduce_operation">Argument name for CO_REDUCE</h3>

<p>
GCC 12 now uses <code>OPERATION</code> as the name of the function to
the <code>CO_REDUCE</code> intrinsic for the pairwise reduction, thus
conforming to the Fortran 2018 standard.  Previous versions
used <code>OPERATOR</code>, which conformed to TS 18508.
</p>

<!--
<h2 id="links">Links</h2>
-->

</body>
</html>
